import { GET, POST } from '@/libs';

import { GENDER, REQUIREMENT } from '@/enum/user';
import { FINISH_STATUS, RECORD_STATUS } from '@/enum/common';
import { STUDY_MATCH_STATUS, TASK_LIST } from '@/enum/study-match';
import { UserInfo } from '@/store/modules/user.module';

export type StudyMatchUserMessge = {
  id?: number;

  userId?: number;

  sex: GENDER;

  age: number;

  height: number;

  home: string;

  phone: string;

  personalTips: string;

  birthday: string;

  college: string;

  nowStay: string;

  createTime?: string;

  updateTime?: string;
};

export const submitUserMessage = (data: StudyMatchUserMessge) => {
  return POST({
    url: '/study-match/submitUserMessage',
    data: data
  });
};

/**
 * 获取个人资料
 * @returns
 */
export const getUserMessage = () => {
  return GET<StudyMatchUserMessge | null>({
    url: '/study-match/getUserMessage'
  });
};

export interface StudyMatchNeedDto {
  id?: number;

  userId?: number;

  requirement: REQUIREMENT;

  city: string;

  sex: GENDER;

  target: string;

  age: string;

  height: string;

  status?: RECORD_STATUS;
}

export const submitStudyMatchNeed = (data: StudyMatchNeedDto) => {
  return POST({
    url: '/study-match/submitStudyMatchNeed',
    data: data
  });
};

/**
 * 获取个人匹配的需求
 * @returns
 */
export const getStudyMatchNeed = () => {
  return GET<StudyMatchNeedDto | null>({
    url: '/study-match/getStudyMatchNeed'
  });
};

export const cancelStudyMatch = () => {
  return POST({
    url: '/study-match/cancelStudyMatch'
  });
};

type InvitationCode = {
  id: number;

  userId: number;

  code: string;

  status: RECORD_STATUS;
};

export const createInvitationCode = () => {
  return POST<InvitationCode | null>({
    url: '/study-match/createInvitationCode'
  });
};

export const matchUserByInvitationCode = (code: string) => {
  return POST({
    url: '/study-match/matchUserByInvitationCode',
    data: {
      code
    }
  });
};

export type StudyMatchResult = {
  id: number;

  matchOne: number;

  matchOneUserInfo: UserInfo;

  matchTwo: number;

  matchTwoUserInfo: UserInfo;

  integral: number;
};

export type StudyMatchStatusResponse = {
  code: STUDY_MATCH_STATUS;
} & Partial<StudyMatchResult>;

export const getStudyMatchStatus = () => {
  return GET<StudyMatchStatusResponse>({
    url: '/study-match/getStudyMatchStatus'
  });
};

type Options = {
  num: number;

  type: TASK_LIST;

  matchId: number;
};

export const addStudyMatchScore = (data: Options) => {
  return POST({
    url: '/study-match/addStudyMatchScore',
    data
  });
};

export type IntegralTaskResponse = {
  id: number;

  matchId: number;

  taskType: TASK_LIST;

  schedule: number;

  integral: number;

  status: FINISH_STATUS;
};

export const getTaskList = (matchId: number) => {
  return GET<IntegralTaskResponse[]>({
    url: '/study-match/getTaskList',
    params: {
      matchId: matchId
    }
  });
};
